|
|
|
| Table C.3 Comparison Operators Used in the WHERE Clause | | Operator | Definition | | < | Less than | | <= | Less than or equal to | | = | Equal to | | >= | Greater than or equal to | | > | Greater than | | <> | Not equal to |
|
|
|
|
|
|
Here is the generic format of the comparison predicate: |
|
|
|
|
|
|
|
|
expression1 comparison-operator expression2 |
|
|
|
|
|
|
|
|
For all comparisons, both expressions must be of the same type (for example, both must be numbers or both must be text strings). Several comparisons of different types are shown in Listing C.9. The comparison values for strings and dates require special formatting. Any strings used in a comparison must be enclosed in single quotes (for example, 'Smith' or 'AL'). Likewise, dates must be enclosed between pound signs (for example, #5/15/94#). The quotes and the pound signs tell the Query engine the type of data that is being passed. Note that numbers do not need to be enclosed within special characters. |
|
|
|
|
|
|
|
|
Listing C.9 COMPARE.TXTComparison Operators Used with Many Types of Data |
|
|
|
|
|
|
|
|
'******************************************************
'Comparison of text data using customer table as source
'******************************************************
SELECT * FROM Customers WHERE Lastname='Smith'
'***************************************************
'Comparison of numeric data using Retail Items table
'***************************************************
SELECT * FROM [Retail Items] WHERE Retail<2
'*****************************************
'Comparison of date data using Sales table
'*****************************************
SELECT * FROM Sales WHERE Date>#8/15/94# |
|
|
|
|
|
|
|
|
With the LIKE predicate, you can compare an expression (that is, a field value) to a pattern. The LIKE predicate lets you make comparisons such as last names starts with S, titles containing SQL, or five-letter words starting with M and ending with H. You use the wild cards * and ? to create the patterns. The actual predicates for these comparisons would be Lastname LIKE 'S*', Titles LIKE '*SQL*', and Word LIKE 'M???H', respectively. |
|
|
|
|
|